package org.project.controller2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.project.pojo.Imgs;
import org.project.pojo.Record0;
import org.project.pojo.Record1;

import org.project.service.user.ImgsService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Controller
@RequestMapping("/firstpage")
public class firstfontcontroller {
@Resource
	private ImgsService imgsService;

public static HttpServletRequest request;


@RequestMapping("/selecteightimgs")
@ResponseBody
public  List<Record1> selecteightimgs(){
	HttpServletRequest req = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
	String path=getLoaclURL(req)+"shell//";
	List<Record1> Record1list=new ArrayList<Record1>();
   	
	List<Record0> list=imgsService.selecteightimgs();
	
	if(list!=null){
	
	Iterator<Record0> it = list.iterator();
	int id=0;
	boolean flag=false;
	while(it.hasNext()) {
		
		Record0 record0= (Record0) it.next();
		Record1 record1=new Record1();
		record1.setFunctionNum(record0.getFunctionNum());
		record1.setUrl(path+record0.getImgName());
		record1.setFunctionName(record0.getFunctionName());
		record1.setEnglishName(record0.getEnglishName());
		record1.setId(id);
		record1.setFlag(flag);
		Record1list.add(record1);
		id++;
	}
	
	}
	return Record1list;
}



    @RequestMapping("/selectbanner")
    @ResponseBody
    public List<Record1> selectbannerings(){
    	HttpServletRequest req = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
    	String path=getLoaclURL(req)+"shell//";
    	List<Record1> Record1list=new ArrayList<Record1>();
    	List<Imgs> list=imgsService.selectbannerimgs();
    	if(list!=null){
    		Iterator<Imgs> it = list.iterator();
    		while(it.hasNext()) {
    			Imgs imgs=(Imgs)it.next();
    			Record1 record1=new Record1();
    			record1.setUrl(path+imgs.getImgName());
    			Record1list.add(record1);
    		}
    	}
    	return Record1list;
    }
    
    
    
    
    
    public static String getLoaclURL(HttpServletRequest request) {
    	
		String path_now = request.getContextPath();
		return request.getScheme() + "://" + request.getServerName() + ":"
				+ request.getServerPort() + path_now + "/";
	}
    
    

}
